package com.foreknow.demo12;

import com.foreknow.demo2.A;
import com.foreknow.demo2.Admin;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapDemo {
    public static void main(String[] args) {
        //创建一个Map容器
//        Map<String,String> maps = new HashMap<>();

        Map<String,Admin> maps = new HashMap<>();
        Admin admin = new Admin();
        admin.setName("tom1");
        Admin admin2 = new Admin();
        admin2.setName("tom2");
        Admin admin3 = new Admin();
        admin3.setName("tom3");
        //向集合中添加元素
//        maps.put("a","tom");
//        maps.put("b","fender");
//        maps.put("c","gibson");

        maps.put("1",admin);
        maps.put("2",admin2);
        maps.put("3",admin3);

        //从集合当中根据key获取到对应的value
//        String name = maps.get("b");
        Admin admin1 = maps.get("2");        Set<Map.Entry<String,Admin>> set = maps.entrySet();
        Iterator<Map.Entry<String,Admin>> it =  set.iterator();
        while(it.hasNext()){
            Map.Entry<String, Admin> entry = it.next();
            String key = entry.getKey();
            Admin ad = entry.getValue();
            System.out.println(key+"------"+ad.getName());
        }
        System.out.println(admin1.getName());
        System.out.println("________________如何遍历map集合———————————————");

    }
}
